package blasthouse.effects;

import java.util.HashMap;

import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.ShapeRenderer;

import blasthouse.characters.Player;
import blasthouse.states.GamePlayState;

public class Attack extends Ability {
	private HashMap<Integer, Rectangle> hitBoxes = new HashMap<Integer, Rectangle>();
	private int nextFrameToAdd = 0;
	
	public Attack(String name, int row, int start, int stop, int speed ){
		super(name, row, start, stop, speed, true, false);		
	}
	
	public void addHitFrame(Rectangle area){
		hitBoxes.put(this.nextFrameToAdd, area);		
		this.nextFrameToAdd++;
	}
	
	public void removeHitFrame(){
		hitBoxes.remove( this.nextFrameToAdd - 1 );
		this.nextFrameToAdd--;
	}
	
	/**
	 * Attempts to remove the numbered frame and collapse the latter frames 
	 * to maintain a smooth continuous animation
	 * @param frame
	 */
	public void removeHitFrame(int frame){
		if( this.nextFrameToAdd <= frame ){ return; }
		
		hitBoxes.remove(frame);
		
		int i = this.nextFrameToAdd - frame - 1;
		for(int n = 0; n < i; n++){
			Rectangle temp = hitBoxes.remove(frame+n);
			hitBoxes.put(frame+n-1, temp);
		}		
	}
	
	public Rectangle getHitBox( int frame ){
		if( frame >= this.nextFrameToAdd ){ return null; }
		float x = hitBoxes.get(frame).getX() + ((Player)GamePlayState.Actors.get(0)).getPlayerSpriteX();
		float y = hitBoxes.get(frame).getY() + ((Player)GamePlayState.Actors.get(0)).getPlayerSpriteY();
		
		return new Rectangle(x, y, hitBoxes.get(frame).getWidth(), hitBoxes.get(frame).getHeight());
	}
}
